import Gain from "../../api/schedules.js";

export default class {
    constructor({ el }) {
        // 接收传入的值添加给this
        this.$el = $(el);
        this.init();
    }
    init() {
        this.render();
    }
    // 初始化页面框架
    render() {
        this.$el.html(
            `
            <div style="margin:40px 100px;">
                <h1>订单信息</h1>
                <table id="schedule" lay-filter="test"></table>
            </div>
            `
        );
        this.rerender();
    }
    layui(data) {
        layui.use('table', function () {
            var table = layui.table;
            //第一个实例
            table.render({
                elem: '#schedule'
                , height: 472,
                width: 1000,
                // ,url: '/demo/table/user/' //数据接口
                data: data
                , page: true //开启分页
                , cols: [[ //表头
                    { field: 'userName', title: '用户', width: 100, sort: true }
                    , { field: 'cinemasId', title: '影院', width: 150, sort: true }
                    , { field: 'theaterId', title: '放映厅', width: 150, sort: true }
                    , { field: 'movieId', title: '影片', width: 150, sort: true }
                    , { field: 'showTime', title: '时间', width: 250, sort: true }
                    , { field: 'price', title: '价格', width: 100, sort: true }
                    , { field: 'seatId', title: '座位', width: 100, sort: true }
                ]]
            });
        });
    }
    // 遍历填充订单数据到新建数组seatsArr中
    async rerender() {
        const data = await Gain.gain()
        const seatsArr = [];
        console.log(data);
        // 排片信息遍历获取填充的值
        data.map((item) => {
            seatsArr.push({
                userName: item.name,
                cinemasId: item.scheduleId[0].cinemasId.name,
                theaterId: item.scheduleId[0].theaterId.name,
                movieId: item.scheduleId[0].movieId.cname,
                price: item.scheduleId[0].price,
                showTime: item.scheduleId[0].showTime,
                seatId: item.seatingsId[0].seatId.name,
            });
        })
        console.log(seatsArr);
        // 调用layui渲染订单数据
        this.layui(seatsArr);
    }
}

